package com.dilidili.controller;


import cn.hutool.core.img.Img;
import com.dilidili.service.IUserService;
import com.dilidili.service.impl.FileUploadService;
import com.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.jab.controller
 * @ClassName: FileUploadController
 * @Author: 零
 * Date: 2022/3/31 14:19
 * project name: osstest
 * @Version:
 * @Description:
 */
@RequestMapping("/oss")
@RestController
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    /*
     * 文件上传api
     */
    @PostMapping("upload")
    public Map<String,Object> upload(@RequestParam("file") MultipartFile file) {
        Map<String,Object> map = new HashMap<>();;
        if (file != null) {
            String returnFileUrl = fileUploadService.upload(file);
            if (returnFileUrl.equals("error")) {
                map.put("error", "文件上传失败！");
                return map;
            }
            map.put("success", "文件上传成功！");
            System.out.println(returnFileUrl);
            map.put("returnFileUrl", returnFileUrl);
            return map;
        } else {
            map.put("error", "文件上传失败！");
            return map;
        }
    }

    /**
     * 删除图片
     * @param
     * @return
     */
    @RequestMapping( value = "deleteFile")
    public String delete(String fileName) {
        System.out.println(11111);
        System.out.println(fileName);
        return fileUploadService.delete(fileName);
    }

    @RequestMapping(value = "aa",method = RequestMethod.PUT)
    public Integer del(Integer id){
      //  System.out.println(id);
        return id;
    }
}
